package com.lvmama.pangolin.controller;


import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import com.github.pagehelper.PageInfo;
import com.lvmama.pangolin.entity.BlackIPConditionVO;
import com.lvmama.pangolin.entity.IP;
import com.lvmama.pangolin.entity.IPListConditionVO;
import com.lvmama.pangolin.entity.IpBlack;
import com.lvmama.pangolin.enums.CommonStringType;
import com.lvmama.pangolin.service.IPService;

@Controller
@RequestMapping("background")
public class IPListController {


	@Autowired 
	private IPService iPService;
	
    @RequestMapping("IPList")
    public String IPList(ModelMap model ,IPListConditionVO iPListConditionVO) throws Exception{
        CommonStringType[] getOffOnType = CommonStringType.getOffOnType();
        //IP状态下拉列表
        List<CommonStringType> offOnTypeList = Arrays.asList(getOffOnType);
        
        if(iPListConditionVO.getiPOffOnVO()==null){
        	iPListConditionVO.setiPOffOnVO("1");
        }
        if(iPListConditionVO.getiPVO()==null){
        	iPListConditionVO.setiPVO("");
        }
        
        PageInfo<IP> page = iPService.getIPList(iPListConditionVO);
        List<IP> iPVOList = page.getList();
        //分页
        model.addAttribute("page", page);
        model.addAttribute("iPVOList", iPVOList);
        model.addAttribute("offOnTypeList", offOnTypeList);
        model.addAttribute("iPListConditionVO",iPListConditionVO);

        return "background/IP/iPVOList";
    }
    
    @RequestMapping("blackIPList")
    public String BlackIPList(ModelMap model ,BlackIPConditionVO blackIPConditionVO) throws Exception{
        CommonStringType[] getBlackIPType = CommonStringType.getBlackIPType();
        //竞品公司代号下拉列表
        List<CommonStringType> BlackIpTypeList = Arrays.asList(getBlackIPType);
        
        CommonStringType[] getOffOnType = CommonStringType.getOffOnType();
        //IP状态下拉列表
        List<CommonStringType> offOnTypeList = Arrays.asList(getOffOnType);
        
        if(blackIPConditionVO.getiPOffOnVO()==null){
        	blackIPConditionVO.setiPOffOnVO("1");
        }
        if(blackIPConditionVO.getiPVO()==null){
        	blackIPConditionVO.setiPVO("");
        }
        if(blackIPConditionVO.getSysCodeVO()==null){  //默认显示XC黑名单
        	blackIPConditionVO.setSysCodeVO("XC");
        }
        
        PageInfo<IpBlack> page = iPService.getBlackIPList(blackIPConditionVO);
        List<IpBlack> iPBlackList = page.getList();
        //分页
        model.addAttribute("page", page);
        model.addAttribute("iPBlackList", iPBlackList);
        model.addAttribute("BlackIpTypeList", BlackIpTypeList);
        model.addAttribute("offOnTypeList", offOnTypeList);
        model.addAttribute("blackIPConditionVO",blackIPConditionVO);

        return "background/IP/BlackIPVOList";
    }
    
    

}
